<template>
	<view>
		<view>
			<uni-forms ref="form" :model="formData" :rules="rules">
				
				<uni-group title="人员基本信息" top="0">
					<uni-collapse-item :title="formData.bisZhsqSnryXm">
						<uni-forms-item label="身份证" label-width="70px" name="bisZhsqSnrySfz" label-align="right">
							<uni-easyinput type="text" v-model="formData.bisZhsqSnrySfz" disabled />
						</uni-forms-item>
						<uni-forms-item label="参保状态" label-width="70px" name="bisZhsqCbzt" label-align="right">
							<uni-easyinput type="text" v-model="formData.bisZhsqCbzt" disabled />
						</uni-forms-item>
						<uni-forms-item label="个人编号" label-width="70px" name="bisZhsqGrbh" label-align="right">
							<uni-easyinput type="text" v-model="formData.bisZhsqGrbh" disabled />
						</uni-forms-item>
						<uni-forms-item label="医保卡号" label-width="70px" name="bisZhsqYbkh" label-align="right">
							<uni-easyinput type="text" v-model="formData.bisZhsqYbkh" disabled />
						</uni-forms-item>
						<uni-forms-item label="参保类型" label-width="70px" name="bisZhsqCblx" label-align="right">
							<uni-easyinput type="text" v-model="formData.bisZhsqCblx" disabled />
						</uni-forms-item>
						<uni-forms-item label="年龄" label-width="70px" name="bisZhsqNl" label-align="right">
							<uni-easyinput type="text" v-model="formData.bisZhsqNl" disabled />
						</uni-forms-item>
						<uni-forms-item label="性别" label-width="70px" name="bisZhsqSnryXb" label-align="right">
							<uni-easyinput type="text" v-model="formData.bisZhsqSnryXb" disabled />
						</uni-forms-item>
					</uni-collapse-item>
				</uni-group>
				<uni-group title="评估信息"  top="0">
					<uni-list>
						<uni-list-item title="ADL分数" :rightText="adlFs"/>
						<uni-list-item showArrow title="ADL量表" :rightText="adlText" clickable  @click="toAdlDForm"/>
						<uni-list-item showArrow title="申请资料" :rightText="formData.isFilePged ? '已查看' : '未查看'" clickable @click="toLiveVideo"/>
					</uni-list>
				</uni-group>
				<uni-group title="申请原因" top="0">
					<uni-forms-item name="bisZhsqSqyy" >
						<uni-easyinput type="textarea" autoHeight v-model="formData.bisZhsqSqyy" disabled/>
					</uni-forms-item>
				</uni-group>
				<uni-group title="评估建议" top="0">
					<uni-forms-item name="bz" >
						<uni-easyinput type="textarea" autoHeight v-model="formData.bz"/>
					</uni-forms-item>
				</uni-group>
			</uni-forms>
			<view class="actionButtonGroup" v-if="editEnable">
				<button class="actionButton" type="warn" @click="formSubmit('-4')">驳回</button>
				<button class="actionButton" type="primary" @click="formSubmit('04')">通过</button>
				<button class="mini-btn action2Button" @click="showDrawer()">查看意见</button>
			</view>
		</view>
	</view>
</template>

<script lang="ts">
	
	import { StorageUtil } from '@/storage/StorageUtil'
	// import { applyFormService } from "@/service/applyForm/ApplyFormService"
	import { route,routeMixin } from "@/route/Route"
	import { assessService } from '@/service/AssessService'
		
	export default {
		mixins:[routeMixin],
		data() {
			return {
				editEnable: false,
				sex: [{
					text: '男',
					value: "0"
				}, {
					text: '女',
					value: "1"
				}],
				adlItems: [],
				adlFs: "",
				adlText: "",
				liveVideoImgs: [],
				userId: '',
				formData: {
					bisZhsqId: '',
					adlZhsqs: [], //ADL表
					bisZhsqAdl: "", //总分
					bisZhsqAdlPc: "", //批次
					bisZhsqGx: "", //用户与失能人员关系
					bisZhsqHldz: "", //失能人员地址
					bisZhsqJhrdh: "", //监护人电话
					bisZhsqJhrxm: "", //监护人姓名
					bisZhsqLxdh: "", //失能人员联系电话
					bisZhsqNl: "", //失能人员年龄
					bisZhsqSnryId: "", //失能人员ID
					bisZhsqSnrySfz: "", //失能人员身份证号
					bisZhsqSnryXb: "", //失能人员性别
					bisZhsqSnryXm: "", //失能人员姓名
					bisZhsqSqyy: "", //备注
					bisZhsqCblx: "", //参保类型
					bisZhsqGrbh: "", // 个人编号
					bisZhsqYbkh: "", // 医保卡号
					bisZhsqCbzt: "", // 参保状态
					bisZhsqSnryYbxxqx: "", // 统筹区
					isAdlPged:false,
					isFilePged: false,
					zpAdl: [],
					pgAdl: [],
					bz:''
				},
				rules: {
					// 对name字段进行必填验证
					name: {
						// name 字段的校验规则
						rules:[
							// 校验 name 不能为空
							{
								required: true,
								errorMessage: '请填写姓名',
							},
							// 对name字段进行长度验证
							{
								minLength: 3,
								maxLength: 5,
								errorMessage: '{label}长度在 {minLength} 到 {maxLength} 个字符',
							}
						],
					}
				}
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: "评估"
			})
			this.refushAdlText()
		},
		methods: {
			routeParameterEvent(data) {
				this.routeParameter = data.zhsq
				this.editEnable = data.editEnable
				if(!this.editEnable){
					this.formData.isAdlPged = true
					this.formData.isFilePged = true
					this.refushAdlText()
				}
				
				this.formData.bisZhsqId = data.zhsq.bisZhsqId
				this.formData.bisZhsqGx = data.zhsq.bisZhsqGx
				this.formData.bisZhsqHldz = data.zhsq.bisZhsqHldz
				this.formData.bisZhsqJhrdh = data.zhsq.bisZhsqJhrdh
				this.formData.bisZhsqJhrxm = data.zhsq.bisZhsqJhrxm
				this.formData.bisZhsqLxdh = data.zhsq.bisZhsqLxdh
				this.formData.bisZhsqNl = data.zhsq.bisZhsqNl
				this.formData.bisZhsqSnryId = data.zhsq.bisZhsqSnryId
				this.formData.bisZhsqSnrySfz = data.zhsq.bisZhsqSnrySfz
				this.formData.bisZhsqSnryXb = data.zhsq.bisZhsqSnryXb
				this.formData.bisZhsqSnryXm = data.zhsq.bisZhsqSnryXm
				this.formData.bisZhsqSqyy = data.zhsq.bisZhsqSqyy
				this.formData.bisZhsqCblx = data.zhsq.bisZhsqCblx
				this.formData.bisZhsqGrbh = data.zhsq.bisZhsqGrbh
				this.formData.bisZhsqYbkh = data.zhsq.bisZhsqYbkh
				this.formData.bisZhsqCbzt = data.zhsq.bisZhsqCbzt
				this.formData.bisZhsqSnryYbxxqx = data.zhsq.bisZhsqSnryYbxxqx
				this.formData.bz = data.zhsq.bz
				
				this.adlFs = data.zhsq.bisZhsqAdl
				
				
				this.userId = StorageUtil.getStorage(StorageUtil.USER_ID)
				for(let adlZhsq of data.zhsq.adlZhsqs){
					if(adlZhsq.bisUserId === data.zhsq.bisUserId){
						this.formData.zpAdl = [...this.formData.zpAdl,adlZhsq]
					}else if(adlZhsq.bisUserId === this.userId){
						this.formData.pgAdl = [...this.formData.pgAdl,adlZhsq]
					}
				}
				if(this.formData.zpAdl.length === this.formData.pgAdl.length){
					this.formData.isAdlPged = true
					this.adlItems = []
					for(let adl of this.formData.pgAdl){
						this.adlItems.push(adl.adlXmxxId);
					}
					this.refushAdlText()
				}
				
			},
			formSubmit: function(e) {
				if(e == '-4' && !this.formData.bz) {
					uni.showToast({
						title: "请填写驳回原因",
						duration: 2000,
						icon:'error'
					});
					return
				}
				let msg = '';
				msg = e === '80' ? '是否确认退回？' : msg;
				msg = e === '-4' ? '是否确认驳回？' : msg;
				msg = e === '04' ? '是否确认提交？' : msg;
				// if(!this.formData.isAdlPged){
				// 	uni.showToast({
				// 		title: "ADL未评估",
				// 		duration: 2000,
				// 		icon:'error'
				// 	});
				// 	return
				// }
				// if(!this.formData.isFilePged){
				// 	uni.showToast({
				// 		title: "图片资料未核实",
				// 		duration: 2000,
				// 		icon:'error'
				// 	});
				// 	return
				// }
				let _this = this
				uni.showModal({
					title: '提示',
					content: msg,
					success: function (res) {
						if (res.confirm) {
							assessService.checkPgjjzh({bisZhsqZt:e,bisZhsqId:_this.formData.bisZhsqId,bz: _this.formData.bz },(resp)=>{
								console.log(resp)
								route.goBack()
							})
						} else if (res.cancel) {
						}
					}
				});
			},
			toAdlDForm(){
				route.navigateTo({name:'adlForm',parameter:{
					bisUserId: this.routeParameter.bisUserId,
					bisZhsqId: this.routeParameter.bisZhsqId,
					bisZhsqAdlPc: this.routeParameter.bisZhsqAdlPc,
					userId: StorageUtil.getStorage(StorageUtil.USER_ID),
					editEnable:this.editEnable
				}})
			},
			toLiveVideo(){
				// this.formData.isFilePged = true
				route.navigateTo({name:'liveVideo',parameter:{
					bisZhsqId: this.routeParameter.bisZhsqId,
					editEnable:this.editEnable
				}})
			},
			refushAdlText(){
				if(this.formData.isAdlPged){
					console.log(this.adlItems)
					assessService.queryScore({adlIds: this.adlItems},(res)=>{
						this.adlFs = res.fs
						if((this.adlFs - 0) < 41){
							this.adlText = "通过"
						}else{
							this.adlText = "未通过"
						}
					})
				}else{
					this.adlText = "未评估"
				}
			},
			fromRouteParameterEvent(id,data) {
				console.log(data)
				if(id == 1){
					this.formData.bisZhsqAdlPc = data.adlPcId
					this.formData.adlZhsqs = data.subItems
					this.adlItems = data.items
					if(this.formData.zpAdl.length === this.adlItems.length){
						this.formData.isAdlPged = true
						
						this.refushAdlText()
						console.log("this.formData.isAdlPged = true")
					}
					console.log(this.formData)
				}
				if(id == 2){
					this.liveVideoImgs = data
					this.formData.isFilePged = true
					console.log(this.liveVideoImgs)
				}
			},
			showDrawer() {
				route.navigateTo({name:'zhsqHistoryList',parameter:{zhsqId:this.formData.bisZhsqId}})
			},
		}
	}
</script>

<style lang="scss">

	.actionButtonGroup{
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		width: -webkit-fill-available
	}
	.actionButton{
		width: 200rpx;
		// margin: 20rpx;
		background-color: $uni-primary;
		color: $uni-white;
	}
	.action2Button{
		width: 280rpx;
		margin-top: 5rpx;
		background-color: blue;
		color: $uni-white;
	}
</style>
